package com.action;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.dao.BaseDAO;
import com.entity.Baoxiu;
import com.entity.Room;
import com.entity.Stu;
import com.entity.Userinfo;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class BaoXiuAction extends ActionSupport {
	Baoxiu data;

	BaseDAO dao = new BaseDAO();

	public String add() {
		data.setCurtime(new Date());
		data.setState("等待处理");
		dao.add(data);
		return show();
	}

	public String del() {
		dao.del(dao.findByID(Baoxiu.class, data.getId()));
		return show();
	}

	public String start() {
		Baoxiu baoxiu = (Baoxiu) dao.findByID(Baoxiu.class, data.getId());
		baoxiu.setState("处理中");
		dao.update(baoxiu);
		return show();
	}

	public String over() {
		Baoxiu baoxiu = (Baoxiu) dao.findByID(Baoxiu.class, data.getId());
		baoxiu.setState("已处理");
		dao.update(baoxiu);
		return show();
	}

	public String show() {
		ActionContext.getContext().put("all", dao.show("from Baoxiu"));
		return SUCCESS;
	}

	
	public String find() {
		String hql = "from Baoxiu where 1=1";
		List params = new ArrayList();
		if(!"".equals(data.getArea())){
			hql+=" and area=?";
			params.add(data.getArea());
		}
		if(!"".equals(data.getFlat())){
			hql+=" and flat=?";
			params.add(data.getFlat());
		}
		if(!"".equals(data.getRoomno())){
			hql+=" and roomno=?";
			params.add(data.getRoomno());
		}
		ActionContext.getContext().put("all", dao.find(hql, params.toArray()));
		return "bao";
	}
	
	public Baoxiu getData() {
		return data;
	}

	public void setData(Baoxiu data) {
		this.data = data;
	}
}
